package api;

import com.alibaba.fastjson.JSON;
import donain.Notice;
import exception.NoticeException;
import exception.ProductException;
import service.NoticeService;
import service.ProductService;
import utilts.Response;
import utilts.ResponseCode;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class GetNoticeServle extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        req.getRequestURL();

        Response build=null;
        NoticeService noticeService=new NoticeService();
        try {
            Notice notice= noticeService.getRecentNotice();
            build=Response.build(ResponseCode.SUCCESS_QUERY_GOODS,notice);

        } catch (SQLException e) {
            e.printStackTrace();
            build=Response.build(ResponseCode.SUCCESS_QUERY_GOODS);
        }


        resp.getWriter().write(JSON.toJSON(build).toString());
        resp.setContentType("application/json;charset=utf-8");


    }
}
